﻿Public Class WindowVariablesValuesRequest

    Public Sub New()
        MyBase.New()
        InitializeComponent()
    End Sub

    Public Shared Sub Fill(ByVal _expression As Enhancements.Basic.Expressions.Expression)
        Dim _window As WindowVariablesValuesRequest = New WindowVariablesValuesRequest()

        For Each _variable As Enhancements.Basic.Expressions.ExpressionVariable In _expression.Variables

            Dim _uniformgrid As Primitives.UniformGrid = New Primitives.UniformGrid
            _uniformgrid.Columns = 2

            Dim _nameLabel As Label = New Label()
            _nameLabel.Content = _variable.Name
            _nameLabel.Padding = Nothing
            _nameLabel.Background = Nothing
            _nameLabel.Foreground = New SolidColorBrush(Colors.White)
            _nameLabel.VerticalContentAlignment = Windows.VerticalAlignment.Center
            _uniformgrid.Children.Add(_nameLabel)

            Dim _valueTextbox As TextBox = New TextBox()
            _valueTextbox.Text = String.Empty
            _uniformgrid.Children.Add(_valueTextbox)

            _window.__VariablesArea.Children.Add(_uniformgrid)

        Next _variable

        _window.ShowDialog()

        For _counter As Integer = 0 To _expression.Variables.Length - 1
            Dim _variableValueAsString As String = CType(CType(_window.__VariablesArea.Children(_counter), Primitives.UniformGrid).Children(1), TextBox).Text
            Select Case _expression.Variables(_counter).UnderlyingType.Name
                Case "Boolean"
                    _expression.Variables(_counter).Value = System.Boolean.Parse(_variableValueAsString)
                Case "DateTime"
                    _expression.Variables(_counter).Value = System.DateTime.Parse(_variableValueAsString)
                Case "Decimal"
                    _expression.Variables(_counter).Value = System.Decimal.Parse(_variableValueAsString)
                Case "Int64"
                    _expression.Variables(_counter).Value = System.Int64.Parse(_variableValueAsString)
                Case "String"
                    _expression.Variables(_counter).Value = _variableValueAsString
            End Select
        Next _counter
    End Sub

    Private Sub __OkButton_Click(ByVal _sender As Object, ByVal _arguments As System.Windows.RoutedEventArgs) Handles __OkButton.Click
        Me.Close()
    End Sub

End Class
